package com.exam.examtest.model

import android.content.Context
import android.os.Build
import androidx.annotation.RequiresApi
import com.blankj.utilcode.util.LogUtils
import com.exam.examtest.contract.MainContract
import com.exam.examtest.util.ConstantValue
import com.exam.examtest.util.IHttpCallback
import com.exam.examtest.util.StringDialogCallback
import com.lzy.okgo.OkGo
import com.lzy.okgo.model.Response

/**
 * ClassName MainModel
 * Create by rhf
 * Create on 2021/3/30 17:01
 * Description 主页面对应的Model层
 */
class MainModel : MainContract.Model {

    override fun getData(mContext: Context?, httpCallback: IHttpCallback) {
        OkGo.get<String>(ConstantValue.BASE_URL)
            .execute(object : StringDialogCallback(mContext) {

                @RequiresApi(Build.VERSION_CODES.KITKAT)
                override fun onSuccess(response: Response<String>) {
                    httpCallback.onSuccess(response.body())
                }

                override fun onError(response: Response<String>) {
                    LogUtils.e("异常信息..." + response.body())
                }
            })
    }
}